<?php

namespace Platform\Models;

/**
 * Model层统一入口类
 * @author Loilee
 * 
 */
class ModelRegist {

    static private $instance = array();  //所有model服务实例
    static private $_instance = null; //当前model服务实例

    /**
     * 
     * @param string $location 服务所在位置
     * @return NULL
     */

    static public function getInstance($location, $param = array()) {
        $md5 = md5(serialize($location . implode('', $param)));

        if (!isset(self::$instance[$md5])) {
            include_once PLATFROM_MODEL_PATH . $location . '.php';

            $namespace = "Platform\\Models\\" . str_replace("/", "\\", $location);

            if (class_exists($namespace)) {
                self::$instance[$md5] = new $namespace($param);
            } else {
                // 类没有定义
                E("未定义命名空间: " . $namespace);
            }
        }
        self::$_instance = self::$instance[$md5];
        return self::$_instance;
    }

}
